package com.zygh.lz.service.impl;


import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zygh.lz.constant.SystemCon;
import com.zygh.lz.dao.*;
import com.zygh.lz.entity.*;
import com.zygh.lz.entity.duty.TaskSchedule;
import com.zygh.lz.entity.remould.Xareas;
import com.zygh.lz.service.XareaService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.vo.ResultBean;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class XareaServiceImpl implements XareaService {
    private static final Log log = LogFactory.get();
    @Resource
    private XareaMapper xareaMapper;
    @Resource
    private StaffMapper staffMapper;
    @Resource
    private PatrolrecordMapper patrolrecordMapper;
    @Resource
    private GpsMapper gpsMapper;
    @Resource
    private XrelationMapper xrelationMapper;
    @Resource
    private SignMapper signMapper;
    @Resource
    private PatrolrecordServiceImpl patrolrecordService;
    @Resource
    private XareaRecordMapper xareaRecordMapper;
    @Resource
    private XareaModeMapper xareaModeMapper;
    @Resource
    private TaskScheduleMapper taskScheduleMapper;
    /**
     * 根据大队，中队，岗位，中队领导
     *
     * @param battalion
     * @param detachment
     * @param station
     * @param leader
     * @return
     */
    @Cacheable(value = "selectfixationRJ")
    @Override
    public ResultBean selectXareabycondition(String battalion, String detachment, String station, String leader, String grid, String type) {
        //查询出来的区域
        List<Xarea> xareas = xareaMapper.selectXareabycondition(battalion, detachment, station, leader, grid, type);
        List<Staff> zg = new ArrayList<>();
        List<Patrolrecord> ydr = new ArrayList<>();
        if (xareas.size() == 0) {
            return ResultUtil.setError(SystemCon.RERROR1, "error", null);
        }
        int conment = 0;
        int num = 0;
        List<Staff> staff;
        //查询该区域的所有民警
        for (int i = 0; i < xareas.size(); i++) {
            //区域内应在岗人数
            staff = staffMapper.selectStaffByxarea(xareas.get(i).getId());
            for (int k = 0; k < staff.size(); k++) {
                //实际在岗人数
                Patrolrecord patrolrecords = patrolrecordMapper.selectPatrolrecordByStaffId(staff.get(k).getSysStaffId());
                //不为空说明在岗
                if (patrolrecords != null) {
                    if (staff.get(k).getSysStaffId() == patrolrecords.getSysStaffId()) {
                        staff.get(k).setStaffOnline("1");
                        //获取gps点
                        Gps gps = gpsMapper.gpsEnd(staff.get(k).getSysStaffId());
                        num++;
                        staff.get(k).setGps(gps);
                    }

                }


            }
            conment += staff.size();
            xareas.get(i).setStaff(staff);

        }
        return ResultUtil.setOK("success", xareas);
    }


    @Override
    public ResultBean insertXarea(Xarea xarea) {
        TaskSchedule taskSchedule = taskScheduleMapper.selectOne(Wrappers.<TaskSchedule>lambdaQuery()
                .eq(TaskSchedule::getDept, xarea.getBattalion())
                .eq(TaskSchedule::getDutyPostCode, xarea.getPostCode()));
        if(Objects.nonNull(taskSchedule)){
            xarea.setRwid(taskSchedule.getRwid());
        }

        if ("夜巡".equals(xarea.getStation())) {
            xarea.setConment("3");
        }
        int i = xareaMapper.insertSelective(xarea);


        if (i > 0) {
            XareaRecord xareaRecord = new XareaRecord();
            xareaRecord.setUpdateBy(xarea.getUpdateBy())
                    .setUpdateTime(new Date())
                    .setXareaId(xarea.getId())
                    .setRecordType(1);
            BeanUtils.copyProperties(xarea, xareaRecord);
            xareaRecordMapper.insert(xareaRecord);
            return ResultUtil.execOp(i, "新增");
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }


    @Override
    public ResultBean updateXarea(Xarea xarea) {
        Xarea xarea1 = xareaMapper.selectByPrimaryKey(xarea.getId());

        TaskSchedule taskSchedule = taskScheduleMapper.selectOne(Wrappers.<TaskSchedule>lambdaQuery()
                .eq(TaskSchedule::getDept, xarea.getBattalion())
                .eq(TaskSchedule::getDutyPostCode, xarea.getPostCode()));
        if(Objects.nonNull(taskSchedule)){
            xarea.setRwid(taskSchedule.getRwid());
        }

        XareaRecord xareaRecord = new XareaRecord();
        xareaRecord.setUpdateBy(xarea.getUpdateBy())
                .setUpdateTime(new Date())
                .setXareaId(xarea.getId())
                .setRecordType(2);
        BeanUtils.copyProperties(xarea1, xareaRecord);
        xareaRecordMapper.insert(xareaRecord);
        return ResultUtil.execOp(xareaMapper.updateById(xarea), "修改");
    }

    @Override
    public ResultBean deleteXarea(Integer id, String updateBy) {

        Xarea xarea1 = xareaMapper.selectByPrimaryKey(id);
        XareaRecord xareaRecord = new XareaRecord();
        xareaRecord.setUpdateBy(updateBy)
                .setUpdateTime(new Date())
                .setXareaId(id)
                .setRecordType(3);
        BeanUtils.copyProperties(xarea1, xareaRecord);
        xareaRecordMapper.insert(xareaRecord);
        //删除该岗位绑定的人员
        int i = xareaMapper.deleteByPrimaryKey(id);
        if (i > 0) {
            xrelationMapper.deleteByXareaid(id);
            return ResultUtil.execOp(i, "删除");
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    @Override
    public ResultBean selectXareaByName(String Name, String battalion, String detachment) {
        List<Xarea> xareas = xareaMapper.selectXareaByName(Name, battalion, detachment);
        if (xareas.size() >= 0) {
            return ResultUtil.setOK("success", xareas);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    @Override
    public ResultBean selectXareaAll() {
        return ResultUtil.setOK("success", xareaMapper.selectXareaAll());
    }


    /**
     * 在线人数
     *
     * @param id
     * @return
     */
    @Override
    public ResultBean selectonlineNumber(Integer id) {
        Map<String, Object> map = new HashMap<>();
        //根据id查询区域
        Xarea xarea = xareaMapper.selectByPrimaryKey(id);
        //查询区域里的应在岗民警
        List<Staff> staff = staffMapper.selectStaffByxarea(xarea.getId());
        //查询区域里实在岗人数
        List<Patrolrecord> online = new ArrayList<>();
        for (int k = 0; k < staff.size(); k++) {
            //实际在岗人数
            Patrolrecord patrolrecords = patrolrecordMapper.selectPatrolrecordByStaffId(staff.get(k).getSysStaffId());
            if (patrolrecords != null) {
                //获取gps点
                Gps gps = gpsMapper.gpsEnd(staff.get(k).getSysStaffId());
                online.add(patrolrecords);
                patrolrecords.setGpsdw(gps);
            }
        }
        map.put("yz", staff);
        map.put("sz", online);
        return ResultUtil.setOK("success", map);
    }

    //按大队显示所有警力
    @Override
    public ResultBean selectpolice() {
        Map<String, Object> map1 = new HashMap<>();
        Map<String, Object> map2 = new HashMap<>();
        Map<String, Object> map3 = new HashMap<>();
        Map<String, Object> map4 = new HashMap<>();
        Map<String, Object> map5 = new HashMap<>();
        Map<String, Object> map6 = new HashMap<>();
        Map<String, Object> map7 = new HashMap<>();


        List<Staff> staff1 = staffMapper.selectStaffYdByAll(null, 25, null);

        List<Staff> staffsd1 = staffMapper.selectStaffByzg(null, null, "一大队");
        List<Staff> staff2 = staffMapper.selectStaffYdByAll(null, 26, null);
        List<Staff> staffsd2 = staffMapper.selectStaffByzg(null, null, "二大队");
        List<Staff> staff3 = staffMapper.selectStaffYdByAll(null, 27, null);
        List<Staff> staffsd3 = staffMapper.selectStaffByzg(null, null, "三大队");
        List<Staff> staff4 = staffMapper.selectStaffYdByAll(null, 28, null);
        List<Staff> staffsd4 = staffMapper.selectStaffByzg(null, null, "四大队");
        List<Staff> staff5 = staffMapper.selectStaffYdByAll(null, 29, null);
        List<Staff> staffsd5 = staffMapper.selectStaffByzg(null, null, "五大队");
        List<Staff> staff6 = staffMapper.selectStaffYdByAll(null, 30, null);
        List<Staff> staffsd6 = staffMapper.selectStaffByzg(null, null, "六大队");

        map1.put("id", 25);
        map1.put("name", "一大队");
        map1.put("ydnum", staff1.size());
        map1.put("sdnum", staffsd1.size());
        map2.put("id", 26);
        map2.put("name", "二大队");
        map2.put("ydnum", staff2.size());
        map2.put("sdnum", staffsd2.size());
        map3.put("id", 27);
        map3.put("name", "三大队");
        map3.put("ydnum", staff3.size());
        map3.put("sdnum", staffsd3.size());
        map4.put("id", 28);
        map4.put("name", "四大队");
        map4.put("ydnum", staff4.size());
        map4.put("sdnum", staffsd4.size());
        map5.put("id", 29);
        map5.put("name", "五大队");
        map5.put("ydnum", staff5.size());
        map5.put("sdnum", staffsd5.size());
        map6.put("id", 30);
        map6.put("name", "六大队");
        map6.put("ydnum", staff6.size());
        map6.put("sdnum", staffsd6.size());
        map7.put("id", 222);
        map7.put("name", "港区大队");
        map7.put("ydnum", 0);
        map7.put("sdnum", 0);

        List<Object> list = new ArrayList<>();
        list.add(map1);
        list.add(map2);
        list.add(map3);
        list.add(map4);
        list.add(map5);
        list.add(map6);
        list.add(map7);
        return ResultUtil.setOK("success", list);
    }

    @Override
    public ResultBean selectks() {
        List<Xarea> selectks = xareaMapper.selectks();
        if (selectks.size() >= 0) {
            return ResultUtil.setOK("success", selectks);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    @Override
    public ResultBean selectqt(String conment, String battalion) {
        //查询出来的区域
        List<Xarea> xareas = xareaMapper.selectqt(conment, battalion);
        List<Staff> zg = new ArrayList<>();
        List<Patrolrecord> ydr = new ArrayList<>();
        if (xareas.size() == 0) {
            return ResultUtil.setError(SystemCon.RERROR1, "error", null);
        }
        int conments = 0;
        int num = 0;
        List<Staff> staff = null;
        //查询该区域的所有民警
        for (int i = 0; i < xareas.size(); i++) {
            //区域内应在岗人数
            staff = staffMapper.selectStaffByxarea(xareas.get(i).getId());
            for (int k = 0; k < staff.size(); k++) {
                //实际在岗人数
                Patrolrecord patrolrecords = patrolrecordMapper.selectPatrolrecordByStaffId(staff.get(k).getSysStaffId());

                if (patrolrecords != null) {
                    if (staff.get(k).getSysStaffId() == patrolrecords.getSysStaffId()) {
                        staff.get(k).setStaffOnline("1");
                        //获取gps点
                        Gps gps = gpsMapper.gpsEnd(staff.get(k).getSysStaffId());
                        num++;
                        staff.get(k).setGps(gps);
                    }

                }
            }
            conments += staff.size();
            xareas.get(i).setStaff(staff);
        }
        return ResultUtil.setOK("success", xareas);
    }

    /**
     * 日间警力部署
     * 固定岗每个大队几个人查询
     *
     * @return
     */
    @Cacheable(value = "selectfixationRJ", key = "'redis_selectfixationRJ_'+#battalion+#station")
    @Override
    public ResultBean selectfixationRJ(String station, String battalion) {
        if ("固定岗".equals(station)) {
            //查询固定岗每个大队几个人
            List<HashMap<String, Object>> list = xareaMapper.selectfixationRJ(station, battalion);


            for (HashMap<String, Object> aList : list) {
                //取出大队
                String sectionName = aList.get("sectionName").toString();
                if (sectionName.contains("大队")) {
                    String sectionName1 = aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    aList.put("sectionName", sectionName1);
                }
                //查询岗位数
                int i1 = xareaMapper.countZSum(station, aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, null);
                aList.put("number", i1);
                //辅警各个大队固定岗人数
                Integer fjddnum = xareaMapper.selectAssistPolice("固定岗", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", null, null).size();
                aList.put("fjnum", fjddnum);
                //细分到中队
                List<HashMap<String, Object>> hashMaps1 = xareaMapper.selectfixationzdRJ(station, aList.get("sectionName").toString());

                for (HashMap<String, Object> aHashMaps1 : hashMaps1) {
                    String dadui = aHashMaps1.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    String substring = aHashMaps1.get("sectionName").toString().substring(sectionName.indexOf("队") + 1, aHashMaps1.get("sectionName").toString().length());
                    //中队详情
                    List<HashMap> hashMaps = xareaMapper.countYDSumby(station, dadui, substring);
                    int num = xareaMapper.countZSumby(station, aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, null);
                    //辅警各个中队人数
                    Integer fjzdnum = xareaMapper.selectAssistPolice("固定岗", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", null, null).size();
                    //如果直属大队下面，没有辅警
                    if (StringUtils.isEmpty(substring)) {
                        fjzdnum = 0;
                    }
                    aHashMaps1.put("fjnum", fjzdnum);
                    aHashMaps1.put("number", num);
                    aHashMaps1.put("detachment", hashMaps);
                    aHashMaps1.put("count", hashMaps.size() == 0 ? 0 : hashMaps.size());
                }
                aList.put("detachment", hashMaps1);
            }

            return ResultUtil.setOK("success", list);

        } else {//高峰岗
            //固定岗每个大队几个人查询
            List<HashMap<String, Object>> list = xareaMapper.selectfixationRJ(station, battalion);

            for (HashMap<String, Object> aList : list) {
                String sectionName = aList.get("sectionName").toString();
                if (sectionName.contains("大队")) {
                    String sectionName1 = aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    aList.put("sectionName", sectionName1);
                }
                //高峰岗部署警力一岗一人
                List<Xarea> xareas = xareaMapper.selectXareapolic(station, aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null);
                aList.put("count", xareas.size());
                //查询岗位数
                int i1 = xareaMapper.countZSum(station, aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, null);
                aList.put("number", i1);
                //辅警高峰岗各大队人数
                Integer fjzdnum = xareaMapper.selectAssistPolice("高峰岗", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", null, null).size();
                aList.put("fjnum", fjzdnum);
                //细分到中队
                List<HashMap<String, Object>> hashMaps1 = xareaMapper.selectfixationzdRJ(station, aList.get("sectionName").toString());
                for (HashMap<String, Object> aHashMaps1 : hashMaps1) {
                    String substring = aHashMaps1.get("sectionName").toString().substring(sectionName.indexOf("队") + 1, aHashMaps1.get("sectionName").toString().length());
                    //高峰岗部署警力一岗一人
                    List<Xarea> xareaes = xareaMapper.selectXareapolic(station, aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring);

                    String dadui = aHashMaps1.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    //各个中队得部署警力
                    int num = xareaMapper.countZSumby(station, aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, null);
                    if (substring.equals("机关")) {
                        System.out.println(station + "|" + aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1) + "|" + substring + "|" + num);
                    }
                    aHashMaps1.put("number", num);
                    List<HashMap> hashMaps = xareaMapper.countYDSumby(station, dadui, substring);
                    aHashMaps1.put("count", hashMaps.size());
                    for (int t = 0; t < hashMaps.size(); t++) {
                        if (!hashMaps.get(t).get("section_name").equals(aHashMaps1.get("sectionName")) || aHashMaps1.get("count") == null) {
                            hashMaps.remove(t);
                            //删除元素后，需要把下标减一。这是因为在每次删除元素后，ArrayList会将后面部分的元素依次往上挪一个位置(就是copy)，
                            // 所以，下一个需要访问的下标还是当前下标，所以必须得减一才能把所有元素都遍历完
                            t--;
                        }
                    }
                    //辅警高峰岗各中队人数
                    Integer fjgzdnum = xareaMapper.selectAssistPolice("高峰岗", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", null, null).size();
                    aHashMaps1.put("detachment", hashMaps);
                    aHashMaps1.put("fjnum", fjgzdnum);
                }
                for (int j = 0; j < hashMaps1.size(); j++) {
                    //大队名称是否一致
                    String detachment = hashMaps1.get(j).get("sectionName").toString().substring(0, hashMaps1.get(j).get("sectionName").toString().indexOf("队") + 1);
                    if (!detachment.equals(aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1))) {
                        hashMaps1.remove(j);
                        j--;
                    }
                }
                for (HashMap aHashMaps1 : hashMaps1) {
                    Object detachment = aHashMaps1.get("detachment");
                    if (detachment == null) {
                        aHashMaps1.remove("sectionName");
                        aHashMaps1.remove("count");
                    }
                }
                aList.put("detachment", hashMaps1);

            }

            return ResultUtil.setOK("success", list);

        }
    }

    /**
     * 重点单位岗
     *
     * @return
     */

    @Cacheable(value = "selectemphasisRJ", key = "'redis_selectemphasisRJ_'+#battalion")
    @Override
    public ResultBean selectemphasisRJ(String battalion) {
        //重点机关岗各个大队人数
        List<HashMap> list = xareaMapper.selectemphasisRJ(battalion);
        //总民警数
        int police = 0;
        int policef = 0;
        for (int i = 0; i < list.size(); i++) {
            String sectionName = list.get(i).get("sectionName").toString();
            if (sectionName.contains("大队")) {
                String sectionName1 = list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                list.get(i).put("sectionName", sectionName1);
            }
            int i1 = xareaMapper.countZSum("重点", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, null);
            list.get(i).put("number", i1);
            //辅警高峰岗各大队人数
            Integer fjddnum = xareaMapper.selectAssistPolice("重点机关岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", null, null).size();
            list.get(i).put("fjnum", fjddnum);
            //各个中队人数
            List<HashMap> hashMaps1 = xareaMapper.selectemphasisZd();

            for (int k = 0; k < hashMaps1.size(); k++) {
                String dadui = hashMaps1.get(k).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                String substring = hashMaps1.get(k).get("sectionName").toString().substring(sectionName.indexOf("队") + 1, hashMaps1.get(k).get("sectionName").toString().length());
                List<HashMap> hashMaps = xareaMapper.selectemphasisPope(dadui, substring);
                for (int t = 0; t < hashMaps.size(); t++) {
                    if (!hashMaps.get(t).get("section_name").equals(hashMaps1.get(k).get("sectionName"))) {
                        hashMaps.remove(t);
                        //删除元素后，需要把下标减一。这是因为在每次删除元素后，ArrayList会将后面部分的元素依次往上挪一个位置(就是copy)，
                        // 所以，下一个需要访问的下标还是当前下标，所以必须得减一才能把所有元素都遍历完
                        t--;
                    }
                }
                int num = xareaMapper.countZSum("重点", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, null);
                //辅警高峰岗各中队人数
                Integer fjzdnum = xareaMapper.selectAssistPolice("重点机关岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", null, null).size();
                hashMaps1.get(k).put("number", num);
                hashMaps1.get(k).put("fjnum", fjzdnum);
                //详情添加到中队里
                hashMaps1.get(k).put("detachment", hashMaps);
                hashMaps1.get(k).put("count", hashMaps.size() == 0 ? 1 : hashMaps.size());
                police += Integer.parseInt(hashMaps1.get(k).get("count").toString());
                policef += fjzdnum;

            }
            //中队详情添加到大队里
            list.get(i).put("detachment", hashMaps1);
            list.get(i).put("count", police);
            list.get(i).put("fjnum", policef);
        }

        return ResultUtil.setOK("success", list);
    }

    /**
     * 日间铁骑
     *
     * @return
     */

    @Cacheable(value = "selectcavalryRJ", key = "'redis_selectcavalryRJ_'+#battalion")
    @Override
    public ResultBean selectcavalryRJ(String battalion) {
        //铁骑
        List<HashMap<String, Object>> list = xareaMapper.selectcavalryRJ(battalion);
        for (HashMap<String, Object> aList : list) {
            String sectionName = aList.get("sectionName").toString();
            if (sectionName.contains("大队")) {
                String sectionName1 = aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                aList.put("sectionName", sectionName1);
            }
            int integers = xareaMapper.countZSum("铁骑", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, null);
            aList.put("number", integers);
            //辅警铁骑各大队人数
            Integer tqddnum = xareaMapper.selectAssistPolice(null, aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", "铁骑", "2").size();
            aList.put("fjnum", tqddnum);
            //各个中队人数
            List<HashMap<String, Object>> hashMaps1 = xareaMapper.selectcavalryzdRJ();
            for (HashMap<String, Object> aHashMaps1 : hashMaps1) {
                String dadui = aHashMaps1.get("sectionName").toString().substring(0, aHashMaps1.get("sectionName").toString().indexOf("队") + 1);
                String substring = aHashMaps1.get("sectionName").toString().substring(aHashMaps1.get("sectionName").toString().indexOf("队") + 1, aHashMaps1.get("sectionName").toString().length());
                List<HashMap> hashMaps = xareaMapper.countYxSum("2", dadui, substring);
                for (int t = 0; t < hashMaps.size(); t++) {
                    if (!hashMaps.get(t).get("section_name").equals(aHashMaps1.get("sectionName"))) {
                        hashMaps.remove(t);
                        //删除元素后，需要把下标减一。这是因为在每次删除元素后，ArrayList会将后面部分的元素依次往上挪一个位置(就是copy)，
                        // 所以，下一个需要访问的下标还是当前下标，所以必须得减一才能把所有元素都遍历完
                        t--;
                    }
                }
                log.info(substring + "----------------------");
                int num = xareaMapper.countZSumby("铁骑", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, null);
                aHashMaps1.put("number", num);
                //详情添加到中队里
                aHashMaps1.put("detachment", hashMaps);
                //辅警铁骑各中队人数
                Integer tqzdnum = xareaMapper.selectAssistPolice(null, aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", "铁骑", "2").size();
                aList.put("fjnum", tqzdnum);
            }
            for (int j = 0; j < hashMaps1.size(); j++) {
                String detachment = hashMaps1.get(j).get("sectionName").toString().substring(0, hashMaps1.get(j).get("sectionName").toString().indexOf("队") + 1);
                if (!detachment.equals(aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1))) {
                    hashMaps1.remove(j);
                    j--;
                }
            }
            aList.put("detachment", hashMaps1);
        }
        return ResultUtil.setOK("success", list);
    }

    /**
     * 日间网格
     * , key="'redis_user_'+#id"
     *
     * @return
     */

    // @Cacheable(value="redisCache",key="'redis_user_'+#battalion")
    @Override
    public ResultBean selectgriddingRJ(String battalion) {
        //网格
        List<HashMap<String, Object>> list = xareaMapper.selectgriddingRJ(battalion);
        for (HashMap<String, Object> aList : list) {
            String sectionName = aList.get("sectionName").toString();
            if (sectionName.contains("大队")) {
                String sectionName1 = aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                aList.put("sectionName", sectionName1);
            }

            int strings = xareaMapper.countZSum("网格", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, null);
            aList.put("number", strings);
            //辅警网格各大队
            Integer wgddnum = xareaMapper.selectAssistPolice("区域", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", "网格", null).size();
            aList.put("fjnum", wgddnum);

            //各个中队人数
            List<HashMap<String, Object>> hashMaps1 = xareaMapper.selectgriddingZD();
            for (HashMap<String, Object> aHashMaps1 : hashMaps1) {
                String dadui = aHashMaps1.get("sectionName").toString().substring(0, aHashMaps1.get("sectionName").toString().indexOf("队") + 1);
                String substring = aHashMaps1.get("sectionName").toString().substring(aHashMaps1.get("sectionName").toString().indexOf("队") + 1, aHashMaps1.get("sectionName").toString().length());
                List<HashMap> hashMaps = xareaMapper.selectgriddingPope(dadui, substring);
                int num = xareaMapper.countZSumby("网格", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, null);
                aHashMaps1.put("number", num);
                //辅警网格各中队
                Integer wgzdnum = xareaMapper.selectAssistPolice("区域", aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", "网格", null).size();
                //详情添加到中队里
                aHashMaps1.put("detachment", hashMaps);
                aHashMaps1.put("fjnum", wgzdnum);
                aHashMaps1.put("count", hashMaps.size());
            }
            for (int j = 0; j < hashMaps1.size(); j++) {
                String detachment = hashMaps1.get(j).get("sectionName").toString().substring(0, hashMaps1.get(j).get("sectionName").toString().indexOf("队") + 1);
                if (!detachment.equals(aList.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1))) {
                    hashMaps1.remove(j);
                    j--;
                }
            }
            aList.put("detachment", hashMaps1);
        }

        return ResultUtil.setOK("success", list);
    }

    /**
     * 日间高速岗
     *
     * @param station
     * @return
     */
    @Override
    public ResultBean selectexpresswayRJ(String station, String battalion) {
        //高速
        List<HashMap> list = xareaMapper.selectexpresswayRJ("高速岗", battalion);
        if (list.size() >= 0) {
            int policef = 0;
            for (int i = 0; i < list.size(); i++) {
                //大队
                String sectionName = list.get(i).get("sectionName").toString();
                if (sectionName.contains("西南绕城高速")) {
                }
                if (sectionName.indexOf("大队") != -1) {
                    String sectionName1 = list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    list.get(i).put("sectionName", sectionName1);
                }
                int strings = xareaMapper.countZSum(station, list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, null);
                list.get(i).put("number", strings);
                //辅警高速各大队
                Integer xngsnum = xareaMapper.selectAssistPolice("高速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", null, null).size();
                list.get(i).put("fjnum", xngsnum);
                //各个中队人数
                List<HashMap> hashMaps1 = xareaMapper.selectexpresswayZD();
                for (int k = 0; k < hashMaps1.size(); k++) {
                    List<HashMap> hashMaps = new ArrayList<>();
                    String dadui = hashMaps1.get(k).get("sectionName").toString().substring(0, hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1);
                    String substring = hashMaps1.get(k).get("sectionName").toString().substring(hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1, hashMaps1.get(k).get("sectionName").toString().length());
                    hashMaps = xareaMapper.selectexpresswayPope("高速岗", dadui, null, substring);
                    for (int t = 0; t < hashMaps.size(); t++) {
                        if (!hashMaps.get(t).get("section_name").equals(hashMaps1.get(k).get("sectionName"))) {
                            hashMaps.remove(t);
                            //删除元素后，需要把下标减一。这是因为在每次删除元素后，ArrayList会将后面部分的元素依次往上挪一个位置(就是copy)，
                            // 所以，下一个需要访问的下标还是当前下标，所以必须得减一才能把所有元素都遍历完
                            t--;
                        }
                    }
                    int num = xareaMapper.countZSum(station, list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, null);
                    hashMaps1.get(k).put("number", num);
                    //详情添加到中队里
                    hashMaps1.get(k).put("detachment", hashMaps);
                    //辅警高速各中队
                    Integer gszdnum = xareaMapper.selectAssistPolice("高速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", null, null).size();
                    hashMaps1.get(k).put("fjnum", gszdnum);
                    policef += gszdnum;
                }
                for (int j = 0; j < hashMaps1.size(); j++) {

                    String detachment = hashMaps1.get(j).get("sectionName").toString().substring(0, hashMaps1.get(j).get("sectionName").toString().indexOf("队") + 1);
                    if (!detachment.equals(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1))) {
                        hashMaps1.remove(j);
                        j--;
                    }
                }

                list.get(i).put("detachment", hashMaps1);
            }

            return ResultUtil.setOK("success", list);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }


    /**
     * 全部在线人警力部署
     *
     * @return
     */
    @Override
    public ResultBean selectInformant() {
        //全部在线人
        List<HashMap> list = xareaMapper.selectInformant();
        if (list.size() >= 0) {
            for (int i = 0; i < list.size(); i++) {
                String sectionName = list.get(i).get("sectionName").toString();
                if (sectionName.indexOf("大队") != -1) {
                    String sectionName1 = list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    list.get(i).put("sectionName", sectionName1);
                }
                //各个中队人数
                List<HashMap> hashMaps1 = xareaMapper.selectInformantZD();
                for (int k = 0; k < hashMaps1.size(); k++) {
                    String dadui = hashMaps1.get(k).get("sectionName").toString().substring(0, hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1);
                    String substring = hashMaps1.get(k).get("sectionName").toString().substring(hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1, hashMaps1.get(k).get("sectionName").toString().length());
                    List<HashMap> hashMaps = xareaMapper.selectInformantPope(dadui, substring);
                    //详情添加到中队里
                    if (dadui.equals(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1))) {
                        hashMaps1.get(k).put("detachment", hashMaps);
                    }

                }
                for (int j = 0; j < hashMaps1.size(); j++) {
                    String detachment = hashMaps1.get(j).get("sectionName").toString().substring(0, hashMaps1.get(j).get("sectionName").toString().indexOf("队") + 1);
                    if (!detachment.equals(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1))) {
                        hashMaps1.remove(j);
                        j--;
                    }
                }
                for (int j = 0; j < hashMaps1.size(); j++) {
                    Object detachment = hashMaps1.get(j).get("detachment");
                    if (detachment == null) {
                        hashMaps1.remove(j);
                        j--;
                    }
                }

                list.get(i).put("detachment", hashMaps1);

            }

            return ResultUtil.setOK("success", list);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    /**
     * 夜间夜巡
     *
     * @return
     */
    @Override
    public ResultBean selectNightTour(String battalion) {
        //夜间夜巡
        List<HashMap> list = xareaMapper.selectNightTour(battalion);
        if (list.size() >= 0) {
            for (int i = 0; i < list.size(); i++) {
                String sectionName = list.get(i).get("sectionName").toString();
                if (sectionName.indexOf("大队") != -1) {
                    String sectionName1 = list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    list.get(i).put("sectionName", sectionName1);
                }

                List<Integer> integers = xareaMapper.countYxZ(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null);
                list.get(i).put("number", integers.size());
                //辅警夜巡
                Integer yxnum = xareaMapper.selectAssistPolice(null, list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", "夜巡", "3").size();
                list.get(i).put("fjnum", yxnum);
                //各个中队人数
                List<HashMap> hashMaps1 = xareaMapper.selectNightTourZD();
                for (int k = 0; k < hashMaps1.size(); k++) {
                    String dadui = hashMaps1.get(k).get("sectionName").toString().substring(0, hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1);
                    String substring = hashMaps1.get(k).get("sectionName").toString().substring(hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1, hashMaps1.get(k).get("sectionName").toString().length());
                    List<HashMap> hashMaps = xareaMapper.selectNightTourPope(dadui, substring);
                    for (int t = 0; t < hashMaps.size(); t++) {
                        if (!hashMaps.get(t).get("section_name").equals(hashMaps1.get(k).get("sectionName"))) {
                            hashMaps.remove(t);
                            //删除元素后，需要把下标减一。这是因为在每次删除元素后，ArrayList会将后面部分的元素依次往上挪一个位置(就是copy)，
                            // 所以，下一个需要访问的下标还是当前下标，所以必须得减一才能把所有元素都遍历完
                            t--;
                        }
                    }
                    List<Integer> num = xareaMapper.countYxZ(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring);
                    hashMaps1.get(k).put("number", num.size());
                    //详情添加到中队里
                    hashMaps1.get(k).put("detachment", hashMaps);
                    //辅警夜巡
                    Integer yxzdnum = xareaMapper.selectAssistPolice(null, list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", "夜巡", "3").size();
                    hashMaps1.get(k).put("fjnum", yxzdnum);
                }
                for (int j = 0; j < hashMaps1.size(); j++) {
                    String detachment = hashMaps1.get(j).get("sectionName").toString().substring(0, hashMaps1.get(j).get("sectionName").toString().indexOf("队") + 1);
                    if (!detachment.equals(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1)) || hashMaps1.get(j).get("detachment") == null) {
                        hashMaps1.remove(j);
                        j--;
                    }

                }
                list.get(i).put("detachment", hashMaps1);

            }

            return ResultUtil.setOK("success", list);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    /**
     * 夜间快速警力部署
     *
     * @param station
     * @return
     */
    @Override
    public ResultBean selectcelerity(String station, String battalion) {
        //夜间快速警力部署
        List<HashMap> list = xareaMapper.selectcelerity(station, battalion);
        if (list.size() >= 0) {
            for (int i = 0; i < list.size(); i++) {
                String sectionName = list.get(i).get("sectionName").toString();
                if (sectionName.indexOf("大队") != -1) {
                    String sectionName1 = list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    list.get(i).put("sectionName", sectionName1);
                }
                List<Integer> integers = xareaMapper.countKsZ("快速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null);
                list.get(i).put("number", integers.size());
                //辅警
                Integer ksgnum = xareaMapper.selectAssistPolice("快速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", null, null).size();
                list.get(i).put("fjnum", ksgnum);
                //各个中队人数
                List<HashMap> hashMaps1 = xareaMapper.selectcelerityPopeZD();
                for (int k = 0; k < hashMaps1.size(); k++) {
                    String dadui = hashMaps1.get(k).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    String substring = hashMaps1.get(k).get("sectionName").toString().substring(hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1, hashMaps1.get(k).get("sectionName").toString().length());
                    List<HashMap> hashMaps = xareaMapper.selectcelerityPope(station, dadui, substring);
                    List<Integer> num = xareaMapper.countKsZ("快速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null);
                    hashMaps1.get(k).put("number", num.size());
                    //详情添加到中队里
                    hashMaps1.get(k).put("detachment", hashMaps);
                    //辅警
                    Integer kszdgnum = xareaMapper.selectAssistPolice("快速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", null, null).size();
                    hashMaps1.get(k).put("fjnum", kszdgnum);
                }
                list.get(i).put("detachment", hashMaps1);

            }

            return ResultUtil.setOK("success", list);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    /**
     * 夜间高速警力部署
     *
     * @param station
     * @return
     */
    @Override
    public ResultBean selectceleritygs(String station, String battalion) {
        //夜间高速警力部署
        List<HashMap> list = xareaMapper.selectceleritygs(station, battalion);
        if (list.size() >= 0) {
            for (int i = 0; i < list.size(); i++) {
                String sectionName = list.get(i).get("sectionName").toString();
                if (sectionName.indexOf("大队") != -1) {
                    String sectionName1 = list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    list.get(i).put("sectionName", sectionName1);
                }
                int integers = xareaMapper.countZSum("高速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, null);
                list.get(i).put("number", integers);
                //辅警高速
                Integer fjgsnum = xareaMapper.selectAssistPolice("高速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", null, null).size();
                list.get(i).put("fjnum", fjgsnum);
                //各个中队人数
                List<HashMap> hashMaps1 = xareaMapper.selectceleritygsPopeZD();
                for (int k = 0; k < hashMaps1.size(); k++) {
                    String dadui = hashMaps1.get(k).get("sectionName").toString().substring(0, hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1);
                    String substring = hashMaps1.get(k).get("sectionName").toString().substring(hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1, hashMaps1.get(k).get("sectionName").toString().length());
                    List<HashMap> hashMaps = xareaMapper.selectceleritygsPope(station, dadui, substring);
                    int num = xareaMapper.countZSum("高速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, null);
                    hashMaps1.get(k).put("number", num);
                    //详情添加到中队里
                    hashMaps1.get(k).put("detachment", hashMaps);
                    //辅警高速
                    Integer fjzdnum = xareaMapper.selectAssistPolice("高速岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", null, null).size();
                    hashMaps1.get(k).put("fjnum", fjzdnum);
                }
                for (int j = 0; j < hashMaps1.size(); j++) {
                    String detachment = hashMaps1.get(j).get("sectionName").toString().substring(0, hashMaps1.get(j).get("sectionName").toString().indexOf("队") + 1);
                    if (!detachment.equals(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1)) || hashMaps1.get(j).get("detachment") == null) {
                        hashMaps1.remove(j);
                        j--;
                    }

                }
                list.get(i).put("detachment", hashMaps1);

            }

            return ResultUtil.setOK("success", list);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    /**
     * 夜间其他警力部署
     *
     * @return
     */
    @Override
    public ResultBean selectqita(String battalion) {
        //夜间其他警力部署
        List<HashMap> list = xareaMapper.selectqita(battalion);
        if (list.size() >= 0) {
            for (int i = 0; i < list.size(); i++) {
                String sectionName = list.get(i).get("sectionName").toString();
                if (sectionName.indexOf("大队") != -1) {
                    String sectionName1 = list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                    list.get(i).put("sectionName", sectionName1);
                }
                Integer fjddnum = xareaMapper.selectqitaPope(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警").size();
                list.get(i).put("fjnum", fjddnum);
                //各个中队人数
                List<HashMap> hashMaps1 = xareaMapper.selectqita(battalion);
                for (int k = 0; k < hashMaps1.size(); k++) {
                    String dadui = hashMaps1.get(k).get("sectionName").toString().substring(0, hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1);
                    String substring = hashMaps1.get(k).get("sectionName").toString().substring(hashMaps1.get(k).get("sectionName").toString().indexOf("队") + 1, hashMaps1.get(k).get("sectionName").toString().length());
                    List<HashMap> hashMaps = xareaMapper.selectqitaPope(dadui, substring, "民警");
                    Integer fjzdnum = xareaMapper.selectqitaPope(dadui, substring, "辅警").size();
                    //详情添加到中队里
                    if (dadui.equals(list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1))) {
                        hashMaps1.get(k).put("detachment", hashMaps);
                    }
                    hashMaps1.get(k).put("fjnum", fjzdnum);
                }
                for (int j = 0; j < hashMaps1.size(); j++) {
                    Object detachment = hashMaps1.get(j).get("detachment");
                    if (detachment == null) {
                        hashMaps1.remove(j);
                        j--;
                    }
                }
                list.get(i).put("detachment", hashMaps1);
            }

            return ResultUtil.setOK("success", list);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    /**
     * 九主六块十六示范区
     *
     * @param station
     * @return
     */
    @Override
    public ResultBean selectDemonstrationPlot(String station, String battalion) {
        List<Xarea> xareas = xareaMapper.selectDemonstrationPlot(station, battalion);
        return ResultUtil.setOK("success", xareas);

    }

    /**
     * 根据区域名字模糊匹配部署警力
     *
     * @param name
     * @return
     */
    @Override
    public ResultBean selctStrength(String name, String battalion) {
        List<HashMap> hashMaps = xareaMapper.selctStrength(name, battalion);
        return ResultUtil.setOK("success", hashMaps);
    }

    /**
     * 九主六块多有人
     *
     * @return
     */
    @Override
    public ResultBean selectAllByDemonstration(String station, String battalion) {
        //根据九主六块查出的区域
        List<Xarea> xareas = xareaMapper.selectDemonstrationPlot(station, battalion);
        List<String> ddNames = xareaMapper.findDd();
        List<HashMap> qyList = new ArrayList<>();
        for (Xarea xarea : xareas) {
            HashMap<String, Object> qyMap = new HashMap<>();
            List<HashMap> ddList = new ArrayList<>();
            for (String ddName : ddNames) {
                HashMap<String, Object> ddMap = new HashMap<>();
                ddMap.put("sectionName", ddName);
                //根据区域名字模糊匹配部署警力
                List<HashMap> list = xareaMapper.selctStrength(xarea.getGridding(), ddName);
                ddMap.put("count", list.size());
                ddMap.put("detachment", list);
                ddList.add(ddMap);
            }

            qyMap.put("ddList", ddList);
            qyMap.put("qyData", xarea.getGridding());
            qyList.add(qyMap);

        }


        return ResultUtil.setOK("success", qyList);
    }

    /**
     * 对接市局接口
     * 根据不同条件查询标注信息
     *
     * @param xarea
     * @return
     */
    @Override
    public ResultBean selectXareaByInfo(Xarea xarea) {
        return ResultUtil.setOK("success", xareaMapper.selectXareaByInfo(xarea));
    }

    @Override
    public ResultBean selectPoliceNumber(Xarea xarea) {
        return ResultUtil.setOK("success", xareaMapper.selectPoliceNumber(xarea));
    }

    //根据区域查询相应警力
    @Override
    public ResultBean selctStrengthById(Xarea xarea) {
        return ResultUtil.setOK("success", xareaMapper.selctStrengthById(xarea));
    }

    /**
     * 任务组信息
     *
     * @return
     */
    @Override
    public ResultBean selectTaskSetInfo() {
        return ResultUtil.setOK("success", xareaMapper.selectTaskSetInfo());
    }

    /**
     * 任务信息
     *
     * @return
     */
    @Override
    public ResultBean selectTaskInfo() {
        return ResultUtil.setOK("success", xareaMapper.selectTaskInfo());
    }

    /**
     * 根据id,大队，岗位查询区域详情
     *
     * @param id
     * @param sectionDid
     * @param grid
     * @return
     */
    @Override
    public ResultBean findDetailsByInfo(Integer id, Integer sectionDid, String grid) {
        List<Regional> detailsByInfo = new ArrayList<Regional>();
        if (grid != null) {
            String substring = grid;
            if (grid.contains("-")) {
                substring = grid.substring(0, grid.indexOf('-'));
            }
            if (grid.contains("网格")) {
                detailsByInfo = xareaMapper.findDetailsByInfo(null, sectionDid, substring);
                for (int i = 0; i < detailsByInfo.size(); i++) {
                    detailsByInfo.get(i).setStation(substring);
                }
            } else {
                detailsByInfo = xareaMapper.findDetailsByInfo(id, null, null);
            }
        }

        return ResultUtil.setOK("success", detailsByInfo);
    }

    /**
     * 根据区域id查询人员详情
     *
     * @param id
     * @return
     */
    @Override
    public ResultBean findStaffInfo(Integer id) {
        List<Dailyservice> staffInfo = xareaMapper.findStaffInfo(id);
        if (staffInfo.size() >= 0) {
            return ResultUtil.setOK("success", staffInfo);
        }
        return ResultUtil.setError(SystemCon.RERROR1, "error", null);
    }

    @Override
    public List<HashMap> countXarea(String rwmc, String battalion, String startTime, String endTime) {
        //当前月份
        Calendar cal = Calendar.getInstance();
        int month = cal.get(Calendar.MONTH) + 1;

        if (rwmc.equals("平峰期")) {
            startTime = startTime + " 07:00:00";
            endTime = endTime + " 20:00:00";
        } else if (rwmc.equals("早高峰")) {
            startTime = startTime + " 07:30:00";
            endTime = endTime + " 08:30:00";
        } else if (rwmc.equals("晚高峰")) {
            if (month == 5 || month == 6 || month == 7 || month == 8 || month == 9) {
                startTime = startTime + " 18:00:00";
                endTime = endTime + " 19:00:00";
            } else {
                startTime = startTime + " 17:30:00";
                endTime = endTime + " 18:30:00";
            }
        } else if (rwmc.equals("夜巡")) {
            startTime = startTime + " 20:00:00";
            endTime = endTime + " 23:59:59";
        } else {
            startTime = startTime + " 00:00:00";
            endTime = endTime + " 23:59:59";
        }

        SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
        long daySum = 0l;
        try {
            long d1 = formater.parse(endTime).getTime();
            long d2 = formater.parse(startTime).getTime();
            //diff=(Math.abs(d1-d2) / (1000 * 60 * 60 * 24));
            daySum = (d1 - d2) / (1000 * 60 * 60 * 24);
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<HashMap> brigadeList = new ArrayList<>();
        // 创建一个数值格式化对象
        NumberFormat numberFormat = NumberFormat.getInstance();
        // 设置精确到小数点后2位
        numberFormat.setMaximumFractionDigits(2);

        int ydSum = 0;
        int sdSum = 0;

        //没有大队名称
        if (StringUtils.isEmpty(battalion)) {
            List<String> ddNames = xareaMapper.findDd();

            for (String ddName : ddNames) {

                List<String> zdNames = xareaMapper.findZd(ddName, null);
                List<String> yxzdNames = xareaMapper.findZd(ddName, "3");
                zdNames.addAll(yxzdNames);

                HashMap<String, Object> ddMap = new HashMap<>();

                List<HashMap> zDList = new ArrayList<>();

                int ddYDSum = 0;
                int ddSDSum = 0;

                //中队名字
                for (String zdName : zdNames) {
                    HashMap<String, Object> zdMap = new HashMap<>();
                    //高峰应到数
                    Integer gfYDsum = xareaMapper.countGFYD(ddName, zdName);
                    //日常勤务平峰期=（【高架大队（郑少+西南）除去事故中队和领导外全部民警人数的三分之一】   +【（机动+网格+固定+铁骑）的民警人数一半】
                    //202		                7         4						                    62   85      22
                    //固定
                    Integer gdYDsum = xareaMapper.countGDYD(ddName, zdName);
                    //固定岗组数
                    Integer gdYDzusum = xareaMapper.countZSum("固定", ddName, zdName, null);
                    //重点
                    Integer zdYDsum = xareaMapper.countZDYD(ddName, zdName);
                    //重点岗位数
                    Integer zdYDjgsum = xareaMapper.countZSum("重点", ddName, zdName, null);
                    //铁骑
                    Integer tqYDsum = xareaMapper.countTQYD(ddName, zdName);
                    //网格
                    Integer wgYDsum = xareaMapper.countWGYD(ddName, zdName);
                    //快速
                    Integer ksYDsum = xareaMapper.countKSYD("高速岗", ddName, zdName);
                    //机动
                    Integer jdYDsum = xareaMapper.countJDYD(ddName, zdName).size() / 2;
                    //其他
                    Integer qtYDsum = xareaMapper.countQtYDSum(ddName, zdName).size() / 2;
                    //夜巡
                    Integer yxYDsum = xareaMapper.countYXYD(ddName, zdName).size();

                    int gdSD = signMapper.countXareaByTime("固定", ddName, startTime, endTime, "民警", zdName);
                    int gfSD = signMapper.countXareaByTime("高峰", ddName, startTime, endTime, "民警", zdName);
                    int tqSD = signMapper.countXareaByTime("铁骑", ddName, startTime, endTime, "民警", zdName);
                    int wgSD = signMapper.countXareaByTime("网格", ddName, startTime, endTime, "民警", zdName);
                    int zdSD = signMapper.countXareaByTime("重点", ddName, startTime, endTime, "民警", zdName);//重点
                    int gsSD = signMapper.countXareaByTime("高速", ddName, startTime, endTime, "民警", zdName);
                    int ksSD = signMapper.countXareaByTime("快速", ddName, startTime, endTime, "民警", zdName);
                    int jdSD = signMapper.countXareaByTime("机动", ddName, startTime, endTime, "民警", zdName);
                    int yxSD = signMapper.countXareaByTime("夜巡", ddName, startTime, endTime, "民警", zdName);


                    int zdYDSum = 0;
                    //高峰岗=高峰岗+固定岗+机动岗+铁骑+重点机关岗
                    // 平峰期=快速+机动+网格+固定+铁骑
                    int zdSDSum = 0;

                    if (rwmc.equals("平峰期")) {

                        //日常勤务 平峰期
                        zdYDSum = ksYDsum + jdYDsum + wgYDsum + gdYDsum + tqYDsum;
                        zdYDSum = (int) (zdYDSum * (daySum + 1));

                        // 平峰期=快速+机动+网格+固定+铁骑
                        zdSDSum = ksSD + jdSD + wgSD + gdSD + tqSD;
                    } else if (rwmc.equals("早高峰")) {
                        //高峰
                        int numtq = tqYDsum / 2;
                        zdYDSum = gfYDsum + gdYDzusum + jdYDsum + numtq + zdYDjgsum;
                        zdYDSum = (int) (zdYDSum * (daySum + 1));

                        zdSDSum = gfSD + gdSD + jdSD + tqSD + zdSD;
                    } else if (rwmc.equals("晚高峰")) {
                        //高峰
                        int numtq = tqYDsum / 2;
                        zdYDSum = gfYDsum + gdYDzusum + jdYDsum + numtq + zdYDjgsum;
                        zdYDSum = (int) (zdYDSum * (daySum + 1));

                        zdSDSum = gfSD + gdSD + jdSD + tqSD + zdSD;
                    } else if (rwmc.equals("夜巡")) {
                        //夜巡
                        zdYDSum = yxYDsum + ksYDsum;
                        zdYDSum = (int) (zdYDSum * (daySum + 1));

                        zdSDSum = yxSD;
                    } else {
                        //全部 高峰岗+固定岗+机动岗+铁骑+重点机关岗+快速+网格+夜巡

                        zdYDSum = gfYDsum + gdYDsum + jdYDsum + tqYDsum + zdYDsum + ksYDsum + wgYDsum + yxYDsum;
                        zdYDSum = (int) (zdYDSum * (daySum + 1));

                        zdSDSum = gfSD + gdSD + jdSD + tqSD + zdSD + ksSD + wgSD + yxSD;
                    }


                    zdMap.put("name", zdName);
                    zdMap.put("YDnum", zdYDSum);
                    zdMap.put("SDnum", zdSDSum);
                    if (zdYDSum == 0) {
                        zdMap.put("gfZXL", 0);
                    } else {
                        zdMap.put("gfZXL", numberFormat.format((float) zdSDSum / (float) zdYDSum * 100));
                    }

                    ddYDSum += zdYDSum;
                    ddSDSum += zdSDSum;

                    zDList.add(zdMap);
                }

                ddMap.put("ddName", ddName);
                ddMap.put("ddYDnum", ddYDSum);
                ddMap.put("ddSDnum", ddSDSum);
                if ((ddYDSum) == 0) {
                    ddMap.put("gfZXL", 0);
                } else {
                    ddMap.put("gfZXL", numberFormat.format((float) ddSDSum / (float) ddYDSum * 100));
                }
                //中队总和
                HashMap<String, Object> zdMap = new HashMap<>();
                zdMap.put("name", "总和");
                zdMap.put("YDnum", ddYDSum);
                zdMap.put("SDnum", ddSDSum);
                if ((ddYDSum) == 0) {
                    zdMap.put("gfZXL", 0);
                } else {
                    zdMap.put("gfZXL", numberFormat.format((float) ddSDSum / (float) ddYDSum * 100));
                }
                zDList.add(zdMap);

                ydSum += ddYDSum;
                sdSum += ddSDSum;

                ddMap.put("zdCount", zDList);
                brigadeList.add(ddMap);
            }
            //大队总和
            HashMap<String, Object> ddzhMap = new HashMap<>();
            ddzhMap.put("ddName", "总和");
            ddzhMap.put("ddYDnum", ydSum);
            ddzhMap.put("ddSDnum", sdSum);
            if ((ydSum) == 0) {
                ddzhMap.put("gfZXL", 0);
            } else {
                ddzhMap.put("gfZXL", numberFormat.format((float) sdSum / (float) ydSum * 100));
            }
            brigadeList.add(ddzhMap);

        } else {
            //有大队名字
            List<String> zdNames = xareaMapper.findZd(battalion, null);

            HashMap<String, Object> ddMap = new HashMap<>();

            List<HashMap> zDList = new ArrayList<>();

            int ddYDSum = 0;
            int ddSDSum = 0;

            //中队名字
            for (String zdName : zdNames) {
                HashMap<String, Object> zdMap = new HashMap<>();
                //高峰应到数
                Integer gfYDsum = xareaMapper.countGFYD(battalion, zdName);
                //日常勤务平峰期=（【高架大队（郑少+西南）除去事故中队和领导外全部民警人数的三分之一】   +【（机动+网格+固定+铁骑）的民警人数一半】
                //202		                7         4						                    62   85      22
                //固定
                Integer gdYDsum = xareaMapper.countGDYD(battalion, zdName);
                //固定岗组数
                Integer gdYDzusum = xareaMapper.countZSum("固定岗", battalion, zdName, null);
                //重点
                Integer zdYDsum = xareaMapper.countZDYD(battalion, zdName);
                //重点岗位数
                Integer zdYDjgsum = xareaMapper.countZSum("重点", battalion, zdName, null);
                //铁骑
                Integer tqYDsum = xareaMapper.countTQYD(battalion, zdName);
                //网格
                Integer wgYDsum = xareaMapper.countWGYD(battalion, zdName);
                //高速
                Integer ksYDsum = xareaMapper.countKSYD("高速岗", battalion, zdName);
                //机动
                Integer jdYDsum = xareaMapper.countJDYD(battalion, zdName).size() / 2;
                //其他
                Integer qtYDsum = xareaMapper.countQtYDSum(battalion, zdName).size() / 2;
                //夜巡
                Integer yxYDsum = xareaMapper.countYXYD(battalion, zdName).size();

                int gdSD = signMapper.countXareaByTime("固定", battalion, startTime, endTime, "民警", zdName);
                int gfSD = signMapper.countXareaByTime("高峰", battalion, startTime, endTime, "民警", zdName);
                int tqSD = signMapper.countXareaByTime("铁骑", battalion, startTime, endTime, "民警", zdName);
                int wgSD = signMapper.countXareaByTime("网格", battalion, startTime, endTime, "民警", zdName);
                int zdSD = signMapper.countXareaByTime("重点", battalion, startTime, endTime, "民警", zdName);//重点
                int gsSD = signMapper.countXareaByTime("高速", battalion, startTime, endTime, "民警", zdName);
                int ksSD = signMapper.countXareaByTime("快速", battalion, startTime, endTime, "民警", zdName);
                int jdSD = signMapper.countXareaByTime("机动", battalion, startTime, endTime, "民警", zdName);
                int yxSD = signMapper.countYXByTime("夜巡", battalion, startTime, endTime, "民警", zdName);


                int zdYDSum = 0;
                int zdSDSum = 0;

                if (rwmc.equals("平峰期")) {

                    //日常勤务 平峰期
                    zdYDSum = ksYDsum + jdYDsum + wgYDsum + gdYDsum + tqYDsum;
                    zdYDSum = (int) (zdYDSum * (daySum + 1));

                    // 平峰期=快速+机动+网格+固定+铁骑
                    zdSDSum = ksSD + jdSD + wgSD + gdSD + tqSD;
                } else if (rwmc.equals("早高峰")) {
                    //高峰
                    int numtq = tqYDsum / 2;
                    zdYDSum = gfYDsum + gdYDzusum + jdYDsum + numtq + zdYDjgsum;
                    zdYDSum = (int) (zdYDSum * (daySum + 1));

                    zdSDSum = gfSD + gdSD + jdSD + tqSD + zdSD;
                } else if (rwmc.equals("晚高峰")) {
                    //高峰
                    int numtq = tqYDsum / 2;
                    zdYDSum = gfYDsum + gdYDzusum + jdYDsum + numtq + zdYDjgsum;
                    zdYDSum = (int) (zdYDSum * (daySum + 1));

                    zdSDSum = gfSD + gdSD + jdSD + tqSD + zdSD;
                } else if (rwmc.equals("夜巡")) {
                    //夜巡
                    zdYDSum = yxYDsum + ksYDsum;
                    zdYDSum = (int) (zdYDSum * (daySum + 1));

                    zdSDSum = yxSD;
                } else {
                    //全部 高峰岗+固定岗+机动岗+铁骑+重点机关岗+快速+网格+夜巡

                    zdYDSum = gfYDsum + gdYDsum + jdYDsum + tqYDsum + zdYDsum + ksYDsum + wgYDsum + yxYDsum;
                    zdYDSum = (int) (zdYDSum * (daySum + 1));

                    zdSDSum = gfSD + gdSD + jdSD + tqSD + zdSD + ksSD + wgSD + yxSD;
                }

                zdMap.put("name", zdName);
                zdMap.put("YDnum", zdYDSum);
                zdMap.put("SDnum", zdSDSum);
                if (zdYDSum == 0) {
                    zdMap.put("gfZXL", 0);
                } else {
                    zdMap.put("gfZXL", numberFormat.format((float) zdSDSum / (float) zdYDSum * 100));
                }

                ddYDSum += zdYDSum;
                ddSDSum += zdSDSum;

                zDList.add(zdMap);
            }

            ddMap.put("ddName", battalion);
            ddMap.put("ddYDnum", ddYDSum);
            ddMap.put("ddSDnum", ddSDSum);
            if ((ddYDSum) == 0) {
                ddMap.put("gfZXL", 0);
            } else {
                ddMap.put("gfZXL", numberFormat.format((float) ddSDSum / (float) ddYDSum * 100));
            }
            //中队总和
            HashMap<String, Object> zdMap = new HashMap<>();
            zdMap.put("name", "总和");
            zdMap.put("YDnum", ddYDSum);
            zdMap.put("SDnum", ddSDSum);
            if ((ddYDSum) == 0) {
                zdMap.put("gfZXL", 0);
            } else {
                zdMap.put("gfZXL", numberFormat.format((float) ddSDSum / (float) ddYDSum * 100));
            }
            zDList.add(zdMap);

            ydSum += ddYDSum;
            sdSum += ddSDSum;

            ddMap.put("zdCount", zDList);
            brigadeList.add(ddMap);

            //大队总和
            HashMap<String, Object> ddzhMap = new HashMap<>();
            ddzhMap.put("ddName", "总和");
            ddzhMap.put("ddYDnum", ydSum);
            ddzhMap.put("ddSDnum", sdSum);
            if ((ydSum) == 0) {
                ddzhMap.put("gfZXL", 0);
            } else {
                ddzhMap.put("gfZXL", numberFormat.format((float) sdSum / (float) ydSum * 100));
            }
            brigadeList.add(ddzhMap);

        }

        //高峰岗=高峰岗+固定岗+机动岗+铁骑+重点机关岗
        // 平峰期=快速+机动+网格+固定+铁骑
        return brigadeList;
    }

    /**
     * 空岗统计 当天没有签到的岗位统计
     *
     * @return
     */
    @Override
    public ResultBean konggangRemind(String battalion) {
        //各大队未签到岗位数
        List<HashMap> hashMaps = xareaMapper.konggangRemind(battalion);
        List<HashMap> hashMaps1 = null;
        for (int i = 0; i < hashMaps.size(); i++) {
            hashMaps1 = xareaMapper.konggangnum(hashMaps.get(i).get("battalion").toString());
            hashMaps.get(i).put("detachment", hashMaps1);
            for (int j = 0; j < hashMaps1.size(); j++) {
                List<HashMap> hashMaps2 = xareaMapper.konggangRemindmend(hashMaps1.get(j).get("sectionname").toString(), hashMaps1.get(j).get("station").toString());
                hashMaps1.get(j).put("detachment", hashMaps2);

            }
        }

        return ResultUtil.setOK("success", hashMaps);
    }

    /**
     * @param nowTime   当前时间
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @author sunran   判断当前时间在时间区间内
     */
    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }

        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 日间机动岗
     *
     * @param battalion
     * @return
     */
    @Cacheable(value = "findMobile", key = "'redis_findMobile_'+#battalion")
    @Override
    public ResultBean findMobile(String battalion) {
        //机动岗每个大队几个人查询
        List<HashMap<String, Object>> list = xareaMapper.selectfixationRJ("机动岗", battalion);

        for (int i = 0; i < list.size(); i++) {
            String sectionName = list.get(i).get("sectionName").toString();
            if (sectionName.indexOf("大队") != -1) {
                String sectionName1 = list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                list.get(i).put("sectionName", sectionName1);
            }
            //查询岗位数
            int i1 = xareaMapper.countZSum("机动", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, null);
            list.get(i).put("number", i1);
            //辅警各个大队固定岗人数
            Integer fjddnum = xareaMapper.selectAssistPolice("机动岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), null, "辅警", null, null).size();
            list.get(i).put("fjnum", fjddnum);
            //细分到中队
            List<HashMap<String, Object>> hashMaps1 = xareaMapper.selectfixationzdRJ("机动岗", list.get(i).get("sectionName").toString());
            for (HashMap<String, Object> aHashMaps1 : hashMaps1) {
                List<HashMap> hashMaps = new ArrayList<>();
                String dadui = aHashMaps1.get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1);
                String substring = aHashMaps1.get("sectionName").toString().substring(sectionName.indexOf("队") + 1, aHashMaps1.get("sectionName").toString().length());
                hashMaps = xareaMapper.countYDSum("机动岗", dadui, substring);
                int num = xareaMapper.countZSumby("机动岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, null);
                //辅警各个中队人数
                Integer fjzdnum = xareaMapper.selectAssistPolice("机动岗", list.get(i).get("sectionName").toString().substring(0, sectionName.indexOf("队") + 1), substring, "辅警", null, null).size();
                aHashMaps1.put("fjnum", fjzdnum);
                aHashMaps1.put("number", num);
                aHashMaps1.put("detachment", hashMaps);
                aHashMaps1.put("count", hashMaps.size() == 0 ? 1 : hashMaps.size());
            }
            list.get(i).put("detachment", hashMaps1);

        }

        return ResultUtil.setOK("success", list);

    }

    @Override
    public ResultBean findAbsent(String station, String battalion) {
        List<HashMap> ddList = new ArrayList<>();

        if (StringUtils.isEmpty(battalion)) {
            List<String> ddNameList = xareaMapper.findDdBystation(station);
            for (String ddName : ddNameList) {
                //大队
                HashMap<String, Object> ddMap = new HashMap<>();
                ddMap.put("name", ddName);
                //查询大队下岗位详情
                List<String> gangNameList = xareaMapper.findGangByName(ddName, station);
                List<HashMap> gangList = new ArrayList<>();
                for (String gangName : gangNameList) {
                    HashMap<String, Object> gangMap = new HashMap<>();
                    int onlineNum = xareaMapper.countByName(gangName, ddName);
                    if (onlineNum <= 0) {
                        gangMap.put("gangName", gangName);
                        gangMap.put("state", "缺勤");
                    }
                    gangList.add(gangMap);
                }
                ddMap.put("gang", gangList);

                ddList.add(ddMap);
            }
        } else {

            //大队
            HashMap<String, Object> ddMap = new HashMap<>();
            ddMap.put("name", battalion);
            //查询大队下岗位详情
            List<String> gangNameList = xareaMapper.findGangByName(battalion, station);
            List<HashMap> gangList = new ArrayList<>();
            for (String gangName : gangNameList) {
                HashMap<String, Object> gangMap = new HashMap<>();
                int onlineNum = xareaMapper.countByName(gangName, battalion);
                if (onlineNum <= 0) {
                    gangMap.put("gangName", gangName);
                    gangMap.put("state", "缺勤");
                }
                gangList.add(gangMap);
            }
            ddMap.put("gang", gangList);
            ddList.add(ddMap);

        }

        return ResultUtil.setOK("success", ddList);
    }

    @Override
    public List<Xarea> findXareaByInfo(String station, Integer id) {
        return xareaMapper.findXareaByInfo(station, id);
    }

    @Override
    public ResultBean selectByPrimaryKey(Integer id) {
        return ResultUtil.setOK("success", xareaMapper.selectByPrimaryKey(id));
    }


    @Override
    public ResultBean findBattalionInfo(String battalion, String station) {
        List<Map> battalionInfo = xareaMapper.findBattalionInfo(battalion, station);
        /*for (Map map : battalionInfo) {
            Xareas xareas = new Xareas();
            xareas.setStation(map.get("station").toString())
                    .setSectionDid(Integer.valueOf(map.get("sectionDid").toString()))
                    .setStaffType("民警");
            //民警警力数
            int policeStrength = xareaMapper.findPoliceStrength(xareas);
            map.put("folkpolice", policeStrength);
            xareas.setStaffType("辅警");
            int policeStrength1 = xareaMapper.findPoliceStrength(xareas);
            map.put("assistpolice", policeStrength1);
        }*/
        return ResultUtil.setOK("success", battalionInfo);
    }

    @Override
    public ResultBean findDetachmentInfo(String sectionDid, String station) {
        List<Map> detachmentInfo = xareaMapper.findDetachmentInfo(sectionDid, station);
        for (Map map : detachmentInfo) {
            Xareas xareas = new Xareas();

            xareas.setStation(map.get("station").toString())
                    .setSectionDid(Integer.valueOf(map.get("sectionDid").toString()))
                    .setSectionZid(map.get("sectionZid") == null ? null : Integer.valueOf(map.get("sectionZid").toString()))
                    .setStaffType("民警");
            //民警警力数
            int policeStrength = xareaMapper.findPoliceStrength(xareas);
            map.put("folkpolice", policeStrength);
            xareas.setStaffType("辅警");
            int policeStrength1 = xareaMapper.findPoliceStrength(xareas);
            map.put("assistpolice", policeStrength1);
        }
        return ResultUtil.setOK("success", detachmentInfo);
    }


    @Override
    public ResultBean findStaffDetail(Xareas xareas) {
        //查询中队下岗位信息
        List<Map> stationInfo = xareaMapper.findStationInfo(xareas.getSectionZid(), xareas.getStation());
        //放入部署民警信息findStaffDetail
        for (Map map : stationInfo) {
            xareas.setGriding(map.get("gridding") == null ? null : map.get("gridding").toString());
            List<Map> policeStrengthInfo = xareaMapper.findPoliceStrengthInfo(xareas);
            map.put("details", policeStrengthInfo);
        }
        return ResultUtil.setOK("success", stationInfo);
    }

    @Override
    public List<Map> findXareaByStation(String sectionId, String station,String name) {
        List<Map> xareaByStation = xareaMapper.findXareaByStation(sectionId, station,name);
        return xareaByStation;
    }

    @Override
    public List<Map> findStation(Integer sectionId) {
        //有岗位的大队
        List<Map> xareaBattalion = xareaMapper.findXareaBattalion(sectionId);
        for (Map map : xareaBattalion) {
            //插入大队含有的岗位
            List<Map> station = xareaMapper.findStation(map.get("sectionDid").toString());
            map.put("detail", station);
        }
        return xareaBattalion;
    }


    @Override
    public List<Map> findXareaCoordinate(String battalion, String station) {
        List<Map> xareaCoordinate = xareaMapper.findXareaCoordinate(battalion, station);
        return xareaCoordinate;

    }

    @Override
    public List<Map> findStaffByXareaId(Integer id) {
        List<Map> findStaffByXareaId = staffMapper.findStaffByXareaId(id);
        return findStaffByXareaId;
    }

    @Override
    public Xarea findXareaById(Integer id) {
        Xarea xarea = xareaMapper.selectByPrimaryKey(id);
        if (xarea == null) {
            return null;
        }
        List<Map> staff = staffMapper.selectStaffByxareaId(id);
        xarea.setUser(staff);
        return xarea;
    }

    @Override
    public Map personnelStatistics(Integer id) {
        List<Map> list = new ArrayList<>();

        String[] station = new String[]{"铁骑", "网格", "高峰岗", "固定岗"};
        for (int i = 0; i < station.length; i++) {
            //岗位名称和岗位数
            Map xareaByType = xareaMapper.findXareaByType(id, station[i]);
            //查询部署民警辅警 警力
            Xareas xareas = new Xareas();
            xareas.setSectionDid(id)
                    .setStation(station[i])
                    .setStaffType("民警");
            int policeStrength = xareaMapper.findPoliceStrength(xareas);
            xareaByType.put("mj", policeStrength);
            xareas.setStaffType("辅警");
            int policeStrength1 = xareaMapper.findPoliceStrength(xareas);
            xareaByType.put("fj", policeStrength1);
            list.add(xareaByType);
        }
        Map map = new HashMap();
        //民警辅警总数
        Xareas xareas = new Xareas();
        xareas.setStaffType("民警").setSectionDid(id);
        int policeStrength = xareaMapper.findPoliceStrength(xareas);
        map.put("totalPolice", policeStrength);
        xareas.setStaffType("辅警");
        int policeStrength1 = xareaMapper.findPoliceStrength(xareas);
        map.put("totalAuxiliary", policeStrength1);
        //总岗位
        Map xareaByType = xareaMapper.findXareaByType(id, null);
        map.put("totalSation", Integer.parseInt(xareaByType.get("count").toString()));

        List<Map> staffByState = signMapper.findStaffByState(null, id);

        String s = patrolrecordService.signIntoRate(staffByState.size(), policeStrength + policeStrength1);
        map.put("onlineRate", s);
        map.put("list", list);
        return map;
    }

    @Override
    public List<XareaMode> findXareaModeAll() {
        return xareaModeMapper.selectList(null);
    }


}
